package com.rpay.web.controller.news;
/**
 * @author XXX
 * @mail XXX@hotmail.com
 * @date 2018/5/7
 * @Description:
*/
import com.rpay.common.dto.news.NewsDTO;
import com.rpay.common.dto.news.SqlQueryDTO;
import com.rpay.common.vo.PcsResult;
import com.rpay.web.service.NewsService;
import com.rpay.web.interceptor.authentic.AccessControl;
import com.rpay.web.interceptor.authentic.AccessControlType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "api/news")
@AccessControl(type = AccessControlType.SECRET)
public class NewsController {

    @Autowired
    private NewsService newsService;

    //获取新闻或公告列表
    @GetMapping(value = "")
//    如果未传值，默认显示新闻列表的数据
    public PcsResult list(
            @RequestParam(name = "type", defaultValue = "") String newsType,
            @RequestParam(name = "page", defaultValue = "1") Integer page,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        SqlQueryDTO data = newsService.data(newsType, page, pageSize);
        return PcsResult.build(data);
    }

    //查看新闻详情
    @GetMapping(value = "/detail/{id}")
    public PcsResult detail(@PathVariable("id") Integer id) {
        NewsDTO newsDetail = newsService.detail(id);
        return PcsResult.build(newsDetail);
    }

}
